package secret.hehe.com.secret.Activity;

import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.RelativeLayout;

import secret.hehe.com.secret.R;
import secret.hehe.com.secret.db.DatabaseHelper;

import static secret.hehe.com.secret.Util.Util.destroyWebView;
import static secret.hehe.com.secret.Util.Util.startWebView;

public class StartActivity extends AppCompatActivity {
    private String webUrl="file:///android_asset/html/Start.html";
    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        Handler x = new Handler();

        DatabaseHelper helper = new DatabaseHelper(this, "my.db", null, 1);
        SQLiteDatabase db = helper.getWritableDatabase();
        //db.execSQL("INSERT INTO user(id,password,icon) VALUES ('1','2','2')");
        //db.execSQL("insert or replace into user values (2,33,4)");
        //db.execSQL("insert or ignore into message values (1,2,1,666,1,666,1666,1,1,'20.01.2017',1,666,1)");
        //db.execSQL("insert or ignore into user VALUES ('2','55','5')");
        webView=new WebView(getApplicationContext());
        RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.start_container);
        startWebView(webView,webUrl,relativeLayout);
        //webView.addJavascriptInterface(this, "android");

        x.postDelayed(new goToLogin(), 3200);//延迟跳转至登录界面
    }
    @Override
    protected void onDestroy(){
        destroyWebView(webView);
        super.onDestroy();
    }
    class goToLogin implements Runnable {
        public void run() {
            startActivity(new Intent(getApplication(), LoginActivity.class));
            StartActivity.this.finish();
        }

    }
}
